<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>医院门诊系统登录页面</title>
    <link href="css/login.css" rel="stylesheet">
</head>

<body>
<div id="loginDiv" style="height: 350px">
    <form id="login">
        <h1 id="loginMsg">医院门诊系统登录</h1>
        <div id="errorMsg"></div>
        <p>手机号:<input id="username" name="username" type="text"></p>
        <p>密码:<input id="password" name="password" type="password"></p>
        <div id="subDiv">
            <button class="button" type="submit">登录</button>&nbsp;&nbsp;&nbsp;
            <a href="patientRegister.html">没有账号？</a>
        </div>
    </form>
</div>

<script src="js/axios-0.18.0.js"></script>

<script>
    document.getElementById("login").addEventListener("submit",function (e){
        e.preventDefault();
        patientLogin();
    });
    function patientLogin(){
        var user = {};
        user.userName = document.getElementById("username").value;
        user.passWord = document.getElementById("password").value;
        axios({
            method:"post",
            url:"/user/patientLogin",
            data:user
        }).then(function (resp) {
            if(resp.data.code == 20051){
                localStorage.setItem("token",resp.data.data)
                window.location.assign("patient.html");
            }else if(resp.data.code == 20050){
                alert(resp.data.msg)
                window.location.assign("patientLogin.html");
            }
        })
    }
</script>

</body>
</html>